package leetcode_core.leetcode_5;

import java.util.Stack;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年01月03日 0:10
 */
public class MinStack {
    private Stack<Integer> g;
    private Stack<Integer> f;
    /** initialize your data structure here. */
    public MinStack() {
        g = new Stack<>();
        f = new Stack<>();
    }

    public void push(int x) {
        g.push(x);
        if(f.isEmpty() || x< f.peek()){
            f.push(x);
        }else{
            f.push(f.peek());
        }
    }

    public void pop() {
        if(g.isEmpty()){
            return;
        }
        g.pop();
        f.pop();
    }

    public int top() {
        return g.peek();
    }

    public int min() {
        return f.peek();
    }
}
